package cn.yunhe.servlet;

import cn.yunhe.dao.IEmpDao;
import cn.yunhe.eneity.Emp;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class JndiServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ApplicationContext ac=new ClassPathXmlApplicationContext("spring.xml");
        IEmpDao empDao= (IEmpDao) ac.getBean("empDao");
        List<Emp> list=empDao.getEmps();
        for (Emp e:list
             ) {
            System.out.println(e.getEmpno()+e.getEname()+e.getJob());

        }



    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
